//
//  WmcMediaUserCenterAPI.swift
//  YPWatermarkCamera
//
//  Created by 周诗松 on 2022/9/14.
//

import Foundation

struct WmcMediaUserCenterAPI {
    /// 统一用户同步信息接口
    /// - DocumentUrl: http://yapi.3pvr.com/project/219/interface/api/3046
    /// - Parameters:
    ///   - userInfo: 用户信息
    /// - Returns: 账号信息model
    static func fetchAccountInfo() -> Observable<WmcAccountModel> {
        return WmcMediaRequest.requestData(path: "/wmc/v1/user/verify") { request in
            request.method = .post
        }.parseModelWithClass(WmcAccountModel.self)
    }

    /// 统一用户同步信息接口
    /// - DocumentUrl: http://yapi.3pvr.com/project/219/interface/api/3046
    /// - Parameters:
    ///   - userInfo: 用户信息
    ///   - success: 请求成功
    ///   - failure: 请求失败
    static func fetchAccountInfo(userInfo: [String: String], success: @escaping ([String: Any]) -> Void, failure: @escaping (YPNetworkError?) -> Void) {
        return WmcMediaRequest.requestData(path: "/wmc/v1/user/verify") { request in
            request.method = .post
            request.extraHeaderFields = userInfo
        } success: { (response: YPNetworkResponse) in
            if let data = response.data as? [String: Any] {
                success(data)
            } else {
                failure(nil)
            }
        } failure: { error in
            failure(error)
        }
    }

    /// 修改头像
    /// - DOcumentUrl: http://yapi.3pvr.com/project/219/interface/api/3481
    /// - Parameter imageUrl: 图片链接
    /// - Returns: Observable<YPNetworkResponse>
    static func updateAvatar(imageUrl: String) -> Observable<YPNetworkResponse> {
        return WmcMediaRequest.requestData(path: "/wmc/v1/user/updateAvatar", parameters: ["avatar": imageUrl]) { request in
            request.method = .post
        }
    }
}
